<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #fullscreen-container {
      width: 150px;
      height: 150px;
      background-color: deeppink;
    }
  </style>
</head>

<body>
  <button id="fullscreen-button">全屏</button>
  <div id="fullscreen-container">
    <!-- 待全屏展示的内容 -->
    <div style="width: 100%;height: 100%;background-color: pink;">

    </div>
  </div>
  <script>
    var fullscreenButton = document.getElementById("fullscreen-button");
    var fullscreenContainer = document.getElementById("fullscreen-container");

    // 进入全屏
    function enterFullscreen() {
      isScreenFull = true
      if (fullscreenContainer.requestFullscreen) {
        fullscreenContainer.requestFullscreen();
      } else if (fullscreenContainer.mozRequestFullScreen) {
        fullscreenContainer.mozRequestFullScreen();
      } else if (fullscreenContainer.webkitRequestFullscreen) {
        fullscreenContainer.webkitRequestFullscreen();
      } else if (fullscreenContainer.msRequestFullscreen) {
        fullscreenContainer.msRequestFullscreen();
      }
    }

    // 退出全屏
    function exitFullscreen() {
      isScreenFull = true
      if (document.exitFullscreen) {
        document.exitFullscreen();
      } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
      } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
      } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
      }
    }

    // 监听按钮点击事件
    fullscreenButton.addEventListener("click", function () {
      enterFullscreen();

    });

    // 监听按键事件
    document.addEventListener("keydown", function (e) {
      if (e.key === "Escape" || e.key === "Esc") {
        exitFullscreen();
      }
    });


  </script>
</body>

</html>